import Vue from 'vue';
import VueRouter from 'vue-router';

/* Layout */
import Layout from '@/layout';

Vue.use(VueRouter);

const routes = [
  {
    path: '/404',
    component: () => import('@/views/common/404'),
    hidden: true,
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '仪表板', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/approve',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Approve',
        component: () => import(/* webpackChunkName: "workflow" */ '@/views/approve'),
        meta: { title: '审批中心', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/workflow',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Workflow',
        component: () => import(/* webpackChunkName: "workflow" */ '@/views/workflow'),
        meta: { title: '流程创建', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/select-user',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'SelectUser',
        component: () => import(/* webpackChunkName: "select-user" */ '@/views/select-user'),
        meta: { title: '选择用户', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/icon-font',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Icon-Font',
        component: () => import(/* webpackChunkName: "icon-font" */ '@/views/icon-font'),
        meta: { title: '字体图标', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/intellect-risk',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Intellect-Risk',
        component: () => import(/* webpackChunkName: "intellect-risk" */ '@/views/intellect-risk'),
        meta: { title: '智能风控', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '例子', icon: 'wechat' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '表格', icon: 'wechat' },
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '树', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '表单', icon: 'wechat' },
      },
    ],
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: { title: '多级嵌套', icon: 'wechat' },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/common/nested'),
        name: 'Menu1',
        meta: { title: 'Menu1' },
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/dashboard/index'),
            name: 'Menu1-1',
            meta: { title: 'Menu1-1' },
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/common/nested'),
            name: 'Menu1-2',
            meta: { title: 'Menu1-2' },
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/dashboard/index'),
                name: 'Menu1-2-1',
                meta: { title: 'Menu1-2-1' },
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/dashboard/index'),
                name: 'Menu1-2-2',
                meta: { title: 'Menu1-2-2' },
              },
            ],
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/dashboard/index'),
            name: 'Menu1-3',
            meta: { title: 'Menu1-3' },
          },
        ],
      },
      {
        path: 'menu2',
        component: () => import('@/views/dashboard/index'),
        name: 'Menu2',
        meta: { title: 'menu2' },
      },
    ],
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: '外链', icon: 'wechat' },
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
];

const router = new VueRouter({
  mode: 'history', // require service support
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes,
});

export default router;
